#include "StdAfx.h"
#include "Patch.h"
#include "User32Hook.h"
#include "WMPHook.h"

#pragma unmanaged

void* SelectUser32Method(int num) {
	void* proc = user32Hook[num];
	if (!proc) {
		proc = user32Save[num];
	}
	return proc;
}

BOOL WINAPI TrackPopupMenuHook(HMENU hMenu, UINT uFlags, int x, int y, int nReserved, HWND hWnd, const RECT *prcRect) {
	SyncFuncHook(BOOL, PTrackPopupMenu, SelectUser32Method(0), (hMenu, uFlags, x, y, nReserved, hWnd, prcRect));
}

LRESULT WINAPI CallWindowProcWHook(WNDPROC lpPrevWndFunc, HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) {
	SyncFuncHook(LRESULT, PCallWindowProcW, SelectUser32Method(1), (lpPrevWndFunc, hWnd, Msg, wParam, lParam));
}

HMENU WINAPI LoadMenuWHook(HINSTANCE hInstance, LPCWSTR lpMenuName) {
	SyncFuncHook(HMENU, PLoadMenuW, SelectUser32Method(2), (hInstance, lpMenuName));
}

INT_PTR WINAPI DialogBoxParamWHook(HINSTANCE hInstance, LPCWSTR lpTemplateName, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam) {
	SyncFuncHook(INT_PTR, PDialogBoxParamW, SelectUser32Method(3), (hInstance, lpTemplateName, hWndParent, lpDialogFunc, dwInitParam));
}

LRESULT WINAPI DispatchMessageWHook(const MSG *lpMsg) {
	SyncFuncHook(LRESULT, PDispatchMessageW, SelectUser32Method(4), (lpMsg));
}

LONG_PTR WINAPI SetWindowLongPtrWHook(HWND hWnd, int nIndex, LONG_PTR dwNewLong) {
	SyncFuncHook(LONG_PTR, PSetWindowLongPtrW, SelectUser32Method(5), (hWnd, nIndex, dwNewLong));
}
